package com.nathan.crm.controller;

import com.nathan.base.BaseController;
import com.nathan.base.ResultInfo;
import com.nathan.crm.query.CustomerLossQuery;
import com.nathan.crm.service.CustomerLossService;
import com.nathan.crm.service.CustomerReprieveService;
import com.nathan.crm.vo.CustomerLoss;
import com.nathan.crm.vo.CustomerReprieve;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("customer_loss")
public class CustomerLossController extends BaseController {
    @Autowired
    private CustomerLossService customerLossService;

    /**
     * 跳转到客户流失管理页面
     * @return
     */
    @RequestMapping("index")
    public String index(){
        return "customerLoss/customer_loss";
    }

    /**
     * 查询客户流失信息
     * @param customerLossQuery
     * @return
     */
    @RequestMapping("list")
    @ResponseBody
    public Map<String,Object> list(CustomerLossQuery customerLossQuery){
        return customerLossService.queryByParamsForTable(customerLossQuery);
    }

    /**
     * 打开客户流失暂缓数据页面
     * @param cusId
     * @return
     */
    @RequestMapping("toCustomerRepPage")
    public String toCustomerRepPage(Integer cusId, Model model){
        // 根据id查询流失客户信息
        CustomerLoss customerLoss = customerLossService.selectByPrimaryKey(cusId);

        model.addAttribute("customerLoss",customerLoss);

        return "customerLoss/customer_rep";

    }

    /**
     * 修改流失客户state为1，表示确定为不可挽回的客户
     * @param id
     * @param lossReason
     * @return
     */
    @RequestMapping("updateCustomerLossStateById")
    @ResponseBody
    public ResultInfo updateCustomerLossStateById(Integer id,String lossReason){
        customerLossService.updateCustomerLossStateById(id,lossReason);
        return success("修改成功！");
    }
}
